package com.harry.configuration.lifecycle;

import static com.harry.configuration.ConstSettings.INITIAL_PACKAGE;

import java.util.Set;

import com.harry.basis.ModuleInitialization;
import com.harry.resource.inner.initialization.InnerModuleInitialization;
import com.harry.utility.ClassUtil;

/**
 * APP启动之后
 */
public class AfterAppLaunch {

	private static boolean runned = false;

	protected void after() throws Exception {
		if (!runned && (runned = true)) run();
	}

	private void run() throws Exception {
		Set<Class<?>> initials = ClassUtil.getClasses(INITIAL_PACKAGE);
		for (Class<?> c : initials) {
			if (c == InnerModuleInitialization.class) {
				((ModuleInitialization) c.getConstructor().newInstance()).initialize();
				break;
			}
		}
		for (Class<?> c : initials) {
			if (c != InnerModuleInitialization.class) {
				((ModuleInitialization) c.getConstructor().newInstance()).initialize();
			}
		}
	}
}
